package com.aasa.siccosap.util;

import java.sql.Connection;
import java.sql.SQLException;

import javax.sql.DataSource;

public class Transaccion {
    
	private Connection objpv_conexion;
	private DataSource objpv_dataSource;
	
	public Transaccion(){
		try{
			this.objpv_dataSource=ServiceLocator.getInstance().getDataSource(Constantes.SICCO_DS);
			this.objpv_conexion=objpv_dataSource.getConnection();
			this.objpv_conexion.setAutoCommit(Boolean.FALSE);
		}
		catch (Exception e) {
			e.printStackTrace();
		}
	}
	
	public Connection getConnection(){
		return objpv_conexion;
	}
	
	public void commit(){
		try {
			objpv_conexion.commit();
		} catch (SQLException e) {
			e.printStackTrace();
		}
	}
	
	public void rollback(){
		try {
			objpv_conexion.rollback();
		} catch (SQLException e) {
			e.printStackTrace();
		}
	}
	
	public void cerrarConexion(){
		try {
			objpv_conexion.close();
			objpv_conexion=null;
		} catch (SQLException e) {
			e.printStackTrace();
		}
	}
	
}
